package com.AAL.DAO;

import java.util.List;

import org.hibernate.classic.Session;

import com.AAL.DAO.Interface.IEvaluationReportDAO;
import com.AAL.Model.Employee;
import com.AAL.Model.EvaluationReport;
import com.AAL.Model.Report;
import com.AAL.Utils.HibernateUtil;

public class EvaluationReportDAO implements IEvaluationReportDAO {

	@Override
	public EvaluationReport saveAndUpdateEvaluationReport(
			EvaluationReport evaluationReport) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		try {
			session.saveOrUpdate(evaluationReport);
		} catch (Exception e) {
			return null;
		}
		session.getTransaction().commit();
		return evaluationReport;
	}

	@Override
	public EvaluationReport deleteEvaluationReport(int evaluationReportID) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		try {
			session.beginTransaction();
			EvaluationReport evaluationReport = (EvaluationReport) session
					.load(EvaluationReport.class, evaluationReportID);
			if (null != evaluationReport) {
				session.delete(evaluationReport);
			}
			session.getTransaction().commit();
			return evaluationReport;
		} catch (Exception e) {
			e.printStackTrace();
			session.getTransaction().rollback();
			return null;
		}
	}

	@Override
	public EvaluationReport getEvaluationReport(int evaluationReportID) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		EvaluationReport evaluationReport = (EvaluationReport) session.load(
				EvaluationReport.class, evaluationReportID);
		return evaluationReport;
	}

	@Override
	public List<EvaluationReport> getLstEvaluationReportByEmployee(
			Employee employee) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<EvaluationReport> getLstEvaluationReportByReport(Report report) {
		// TODO Auto-generated method stub
		return null;
	}

}
